1
选课报告任务简介
DSAI2202Lab 6: Connecting Related Data

教务处将学生档案、课程详情和选课记录分别存放在不同的表中。请构建一份报告,把 正确的学生姓名与对应的课程对应起来。

你的三项需求

  1. 查找 Emma Li 的有效课程。
  2. 列出所有有效选课记录,并附上学生姓名和课程名称。
  3. 生成 DSAI 学生 PY101 有效选课名单。

准备 PostgreSQL

  1. 在 pgAdmin 中,打开 TA 文件夹 lab6_7_setup.sql 中提供的 DSAI2202/lab6_7/ 并完整运行该文件一次。
  2. 确认最终记录数: 22 名学生、8 门课程、37 条选课记录对应起来。
  3. 运行右侧的连接设置。每次建立新的数据库连接时都要重新运行它。
  4. 在连接这三张表之前,先查看它们的内容。

实验 7 会使用相同的初始化脚本,其中包括 assignments、 submissions, and lms_roster. Today, use the three tables shown here. All people and records are fictional.

✍️ Trace Before You Join
Find enrolment E01. Which student ID and course code does it contain? Use the Data tab to recover the student's name and the course title.
Set schema
SET search_path TO lab6_7;
Students
SET search_path TO lab6_7;

SELECT student_id, student_name, programme
FROM students
ORDER BY student_id;
Courses
SET search_path TO lab6_7;

SELECT course_code, course_title, credits
FROM courses
ORDER BY course_code;
Enrolments
SET search_path TO lab6_7;

SELECT enrolment_id, student_id, course_code,
       enrolment_status, score
FROM enrolments
ORDER BY enrolment_id;